#include <iostream>

void usage();
void useConst(const char *msg);

class Time {
  int year_;

public:
  // const 成员函数
  int getYear() const { return year_; }
};

// 类成员变量初始化方式
class Person {
  const char *name_ = "Alice";
  int age_;

public:
  Person() : age_{20} {}
  Person(const char *name, int age) : name_{name}, age_{age} {}
};

int main(int argc, char *argv[]) {
  std::cout << "==== ch03 p03 ====" << std::endl;
  printf("---- usage() ----\n");
  usage();
  printf("---- useConst() ----\n");
  char msg[] = "hello world";
  useConst(msg);
  return 0;
}

void usage() {
  int a{10};
  int &ra{a};
  int newA{20};
  ra = newA; // 注意, 这里并非将 ra 指向 newA, 而是将 a 的值改为 newA
  printf("a = %d, ra = %d, newA = %d\n", a, ra, newA); // 20, 20, 20
}

void useConst(const char *msg) {
  // 只读使用, OK
  printf("msg is %s\n", msg);
  // 尝试修改, 编译报错
  // msg[0] = 'h';
}
